The stack's restricted access, mandated by the FILO principle, is strictly enforced through a standardized set of procedures.
- All primary stack manipulation operations center around updating the
topindex, which maintains the state of the stack. - The five fundamental stack operations are:
- Primary Operations (Manipulation):
push: Inserts a new element at the index $top + 1$.pop: Removes the element currently pointed to bytopand then decrements the pointer.- Helper Operations (Status Checks):
peek(ortop): Returns the value at the currenttopposition without removing it.isEmpty: A check ensuring no underflow occurs ($top == -1$).isFull: A check ensuring no overflow occurs ($top == n - 1$).
Fundamental Stack Operations
| Operation | Description |
|---|---|
push(element) |
Adds an element to the top of the stack. |
pop() |
Removes and returns the top element. |
peek() |
Returns the top element without removing it. |
isEmpty() |
Checks if the stack is empty. |
isFull() |
Checks if the stack has reached its capacity. |